<?php

namespace app\admin\service\statistics\datatable\lawsuit;


use app\admin\service\statistics\datatable\AbstractComputeStatistician;
use app\admin\service\statistics\traits\CompletionTrait;


/**
 * 付费占比
 * Class LawsuitConsultingPaidRate
 * @package app\admin\service\statistics\datatable\lawsuit
 */
class LawsuitConsultingPaidRate extends AbstractComputeStatistician
{
    // 前置数据
    protected array $statisticians = [
        'consulting_count' => LawsuitConsultingCount::class,
        'consulting_paid_count' => LawsuitConsultingPaidCount::class,
    ];

    // 补齐
    use CompletionTrait;

    protected function compute(int $index)
    {
        $statisticiansData = $this->statisticiansData;

        $consulting_count = $statisticiansData['consulting_count'][$index]['value'] ?? null;

        $consulting_paid_count = $statisticiansData['consulting_paid_count'][$index]['value'] ?? null;

        if (!is_numeric($consulting_count) || !is_numeric($consulting_paid_count)) {
            return '';
        }

        return show_percentage($consulting_paid_count, $consulting_count, 1);
    }

    protected function getDefaultValue()
    {
        return '0%';
    }
}